package com.firstjianmo.listviewtest;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    private List<ListItem> itemGroup = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initItemGroup();

        ListItemAdapter adapter = new ListItemAdapter(MainActivity.this, R.layout.mlist_item, itemGroup);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ListItem listOneItem = itemGroup.get(position);
                Toast.makeText(MainActivity.this, listOneItem.getMsg(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initItemGroup() {
        for (int i = 0; i < 20000; i++) {
            itemGroup.add(new ListItem("测试"+i, R.mipmap.ic_launcher));
        }

    }
}
